#include "StdAfx.h"
#include "AIPlayer.h"
#include "Game.h"
#include "AIRandomPlayer.h"
#include "AINovicePlayer.h"


AINovicePlayer::AINovicePlayer() : AIRandomPlayer(){}

void AINovicePlayer::play(sf::RenderWindow & window, Piece *piece, std::vector<Piece> &m_pieces)
{
	Location *loc;
	if(Game::thereArePiecesLeft())
	{
		/*if((((*piece).getLocation()).first==4) && (((*piece).getLocation()).second==4))
		{*/
		do
		{
			//malloc the new location...
			loc = (Location *)malloc(sizeof(Location));
			srand((unsigned)time(0));
			do
			{	
				//select a free space on the board	
				loc->first = rand()%4;
				loc->second = rand()%4;
			}
			while(Game::thereIsPiece(*loc));
			//setting the new location for the piece
			(*piece).setLocation(*loc);
		}
		while(AIPlayer::evalutateState(m_pieces) == AIPlayer::INFINITY);
			this->increaseTurnCount();
		//}

	}
	return;
}

Piece *AINovicePlayer::choosePiece(sf::RenderWindow & window, std::vector<Piece> &m_pieces)
{
	return	this->AIRandomPlayer::choosePiece(window, m_pieces);
}